package com.woniuxy.Response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @auther linke
 * @create 2021-10-19 12:53
 */
@WebServlet("/responseDemo03")
public class ResponseDemo03  extends HttpServlet {
    /**
     *写出响应参数
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

       /* //初始版本
        resp.setCharacterEncoding("utf-8");
        //设置响应头，告诉浏览器应该用什么类型解析
        resp.setHeader("content-type","text/html;charset=utf-8");

        PrintWriter pw = resp.getWriter();
        pw.write("清风明月");*/

      /* //第二版
       resp.setHeader("content-type","text/html;charset=utf-8");
       resp.getWriter().write("清风明月");*/

       //最终版
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().write("清风明月");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
